package 力扣日常刷题.木22二月.第02天207;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 * 时间累计 如果+ > -   可以添加一天
 */
public class Demo28贪心做菜顺序 {


    public int maxSatisfaction(int[] satisfaction) {
        Arrays.sort(satisfaction);
        int presum = 0,ans = 0;
        for (int i = satisfaction.length - 1; i >= 0; i--) {
            int si = satisfaction[i];
            if(presum + si >= 0){
                presum += si;
                ans += presum;
            }else {
                break;
            }
        }
        return ans;
    }

}
